/*
 *
 * @Date: 2022-06-09 19:42:19
 * @LastEditTime: 2022-06-19 20:32:19
 */
import {Component, OnInit} from '@angular/core';
import {Router} from '@angular/router';
import {PostItem} from "../../model/post-item";
import {ApiPath} from "../../config/api-path";
import * as dayjs from "dayjs";
import {Campus} from "../../enum/campus";
import {HttpService} from "../../service/http.service";

@Component({
  selector: 'app-ask-container',
  templateUrl: './ask-container.component.html',
  styleUrls: ['./ask-container.component.scss'],
})
export class AskContainerComponent implements OnInit {
  constructor(
    private HttpSrv: HttpService,
    private router: Router,
  ) {
  }

  ngOnInit() {
    this.initi();
  }

  AskDataLs: PostItem[];

  initi() {
    this.HttpSrv.httpGet<PostItem[]>(ApiPath.request.forum.recentPosts,{type: "a"})
      .subscribe(res => {
        if ('data' in res) {
          const ls: PostItem[] = res.data;
          ls.map(item => {
            item.headImgUrl = ApiPath.IMAGE_SERVER_PATH + item.headImgUrl;
            item.appointedTime = dayjs(item.appointedTime).format('MM-DD HH:mm');
            item.campus = Campus[item.campus];
          });
          this.AskDataLs = ls;
          console.debug(this.AskDataLs);
        }
      });
  }

  gotoCreate() {

    this.router.navigate(['/create', "ask"]).then(() => {
    });
  }

  gotoDetails(index) {
    // this.router.navigateByUrl()
    this.router.navigate(['/detail', index]).then(() => {
    });
  }
}
